#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"
#include "key.h"
//#include "OLED_Font.h"
//4-1 读写备份寄存器
uint16_t Array_W[]={0x1234,0x5678};
uint16_t Array_R[2];

uint8_t Key;
int main(void){
	OLED_Init();
	Key_Init();
	
	OLED_ShowString(1,1,"W:");
	OLED_ShowString(2,1,"R:");
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP,ENABLE);
	
	PWR_BackupAccessCmd(ENABLE);
	
	while(1){
		Key=Key_GetNum();
		if(Key==1){
			Array_W[0]++;
			Array_W[1]++;
			
			BKP_WriteBackupRegister(BKP_DR1, Array_W[0]);
			BKP_WriteBackupRegister(BKP_DR2, Array_W[1]);
			
			OLED_ShowHexNum(1,3,Array_W[0],4);
			OLED_ShowHexNum(1,8,Array_W[1],4);
		}
		
		Array_R[0]=BKP_ReadBackupRegister(BKP_DR1);
		Array_R[1]=BKP_ReadBackupRegister(BKP_DR2);
		
		OLED_ShowHexNum(2,3,Array_R[0],4);
		OLED_ShowHexNum(2,8,Array_R[1],4);
		
	}
}
